package com.jf.furn.service.impl;

import com.jf.furn.bean.Furniture;
import com.jf.furn.bean.FurnitureExample;
import com.jf.furn.dao.FurnitureMapper;
import com.jf.furn.service.FurnitureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-11-18
 * Time:10:40
 */
@Service
public class FurnitureServiceImpl implements FurnitureService {
    @Autowired
    private FurnitureMapper furnitureMapper;
    @Override
    public void save(Furniture furniture) {
        furnitureMapper.insertSelective(furniture);
    }

    @Override
    public List<Furniture> getAllFurniture() {
        return furnitureMapper.selectByExample(null);
    }

    @Override
    public List<Furniture> getFurnitureByName(String furnitureName) {
        FurnitureExample furnitureExample = new FurnitureExample();
        FurnitureExample.Criteria criteria = furnitureExample.createCriteria();
        if (StringUtils.hasText(furnitureName)) criteria.andNameLike("%"+furnitureName+"%");
        return furnitureMapper.selectByExample(furnitureExample);
    }

    @Override
    public int updateFurniture(Furniture furniture) {
        return furnitureMapper.updateByPrimaryKey(furniture);
    }

    @Override
    public int deleteFurnitureById(int id) {
        return furnitureMapper.deleteByPrimaryKey(id);
    }
}
